package com.wsl.sale.redis.service;

import com.wsl.sale.redis.entity.Hello;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

/**
 * @Author:wangshuliang
 * @Description:
 * @Date:Created in 10:52 2019/5/8
 * @Modified by:
 */
@Service
public class HelloService {
    @CachePut(value="hello",key = "#hello.name")
    public Hello put(Hello hello){
        System.out.println("put hello:" + hello.getName());
        return hello;
    }

    @Cacheable(value="hello",key = "#name")
    public Hello get(String name){
        System.out.println("new Hello:"+name);
        return new Hello(name);
    }

    /**
     * 从命名为Hello的缓存中，删除掉name参数的key
     * @param name
     */
    @CacheEvict(value = "hello",key = "#name")
    public void remove(String name){
        System.out.println("remove Hello:"+name);
    }

    /**
     * 从命令为hello的缓存中删除所有缓存
     */
    @CacheEvict(value = "hello",allEntries = true)
    public void removeAll(){
        System.out.println("remove all");
    }

}
